import pickle
execfile('reduction_utils3.py', globals())

methanol_trans=pickle.load(open("methanol_transitions.pickle", "rb"))




vislist=['V883_Ori_SB1_spectral_line.ms','V883_Ori_SB2_spectral_line.ms']
for vis in vislist:
   for key in methanol_trans.keys():
      mstransform(vis=vis,spw='7',regridms=True,mode='velocity',nchan=53,outframe='LSRK',veltype='radio',\
                  restfreq=str(methanol_trans[key]['freq'])+'Hz',start='0km/s',width='0.16km/s',\
                  outputvis=vis.replace('.ms','.'+key+'_LSRK.ms'),datacolumn='data')

SB_scales = [0, 5]  #[0, 5, 30, 100, 200]

sidelobethreshold=2.0
noisethreshold=4.0
lownoisethreshold=1.0 
smoothfactor=2.0
parallel=True

import glob
vislist=glob.glob('*_LSRK.ms')
vislist.sort()
concat(vis=vislist,freqtol='1GHz',concatvis='V883_Ori_CH3OH_line_stack.ms')

cellsize='0.0075arcsec'
imsize=768
for robust in [0.5,1.0,2.0]:
   imagename = 'V883_Ori_SB_CH3OH_stacked_robust_'+str(robust)
   tclean_spectral_line_wrapper('V883_Ori_CH3OH_line_stack.ms', imagename,
                '0.0km/s', '0.16km/s', -1, '241806.524MHz', 
                '0', SB_scales, nsigma=3.0,
                imsize=imsize, cellsize=cellsize,robust=robust, 
                sidelobethreshold=sidelobethreshold, noisethreshold=noisethreshold,
                lownoisethreshold=lownoisethreshold,smoothfactor=smoothfactor,parallel=parallel,
                phasecenter='ICRS 05h38m18.100454s -07d02m25.99340s')


